var e = getApp().requirejs("core");

Page({
  data: {
    showimage: !1,
  },
  onLoad: function(e) {},
  onShow: function() {
    this.getData();
  },
  getData: function() {
    var o = this;
    e.get("commission/qrcode", {}, function(e) {
      70001 != e.error ? (e.show = !0, o.setData(e), o.getImage()) : wx.redirectTo({
        url: "/pages/member/info/index"
      });
    });
  },
  getImage: function() {
    var o = this;
    e.post("commission/qrcode", {}, function(e) {
      70001 != e.error ? (e.showimage = !0, o.setData(e)) : wx.redirectTo({
        url: "/pages/member/info/index"
      });
    });
  },
	longpress(e) {
		wx.getSetting({
			success: function (res) {
				wx.authorize({
					scope: 'scope.writePhotosAlbum',
					success: function (res) {
						console.log("授权成功");
						var imgUrl = e.currentTarget.dataset.img;
						wx.showActionSheet({
							itemList: ['保存到相册'],
							success: function (res) {
								wx.showLoading({
									title: '保存中',
								})
								wx.downloadFile({
									url: imgUrl,
									success: function (res) {
										wx.hideLoading();
										// 下载成功后再保存到本地
										wx.saveImageToPhotosAlbum({
											filePath: res.tempFilePath,
											success: function (res) {
												wx.showToast({
													title: '成功保存到相册',
													icon: 'success'
												})
											}
										})
									}
								})
							},
							fail: function (res) {
								console.log(res.errMsg)
							}
						})
					}
				})
			}
		})
	}
});